package max.ubitest.pipe.commands
{
	import max.ubitest.pipe.data.ComponentData;
	import max.ubitest.pipe.events.PipeEvent;
	import max.ubitest.pipe.locators.ComponentsLocator;
	
	import org.robotlegs.mvcs.Command;
	
	public class SelectComponentCommand extends Command
	{
		[Inject]
		public var event:PipeEvent;
		[Inject]
		public var locator:ComponentsLocator;
		
		public function SelectComponentCommand()
		{
			super();
		}
		
		override public function execute():void{
			if(locator.selectedComponent){
				/*if(locator.selectedComponent.type == event.data.type){
					event.data.amount ++ ;
					locator.selectedComponent = null;
					return;
				}else{
					return;
				}*/
				dispatch(new PipeEvent(PipeEvent.COMPONENT_UNSELECTED, null));
				return;
			}
			event.data.amount -- ;
			locator.selectedComponent = (event.data as ComponentData).clone() as ComponentData;
		}
	}
}